<template>
  <div>
    <div class="history">
      <div class="top">
        <h4>历史记录</h4>
        <van-icon name="delete-o" @click="clearFn" />
      </div>
      <div class="down" v-if="ifShowHistory">
        <van-tag
          v-for="(item, index) in historyKeywordList"
          @click="tagClick(item)"
          :key="index"
          plain
          type="default"
          >{{ item }}</van-tag
        >
      </div>
    </div>

    <div class="history">
      <div class="top">
        <h4>热门搜索</h4>
      </div>
      <div class="down">
        <van-tag
          v-for="(item, index) in hotKeywordList"
          @click="tagClick(item.keyword)"
          :key="index"
          plain
          :type="item.is_hot == 1 ? 'danger' : 'default'"
          >{{ item.keyword }}</van-tag
        >
      </div>
    </div>
  </div>
</template>

<script>
import { ClearHistory } from "@/api";
export default {  
  name: "HistoryHot",
  props: ["historyKeywordList", "hotKeywordList"],
  data() {
    return {
      ifShowHistory: true,
    };
  },
  methods: {
    // 点击tag后进行搜索事件
    tagClick(item) {
      this.$emit("tagClick", item);
    },
    // 清除历史记录
    clearFn() {
      ClearHistory().then((res) => {
        this.$toast.success("删除成功");
        setTimeout(() => {
          this.ifShowHistory = false;
        }, 500);
      });
    },
  },
};
</script>

<style lang="less" scoped>
.history {
  padding: 0 2%;
  background-color: #fff;
  margin-bottom: 0.2rem;
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 0.5rem;
    font-size: 0.2rem;
    h4 {
      font-weight: normal;
      font-size: 0.18rem;
    }
  }
  .down {
    .van-tag {
      font-size: 0.14rem;
      margin-right: 0.1rem;
      margin-bottom: 0.1rem;
      padding: 0.03rem;
    }
  }
}
</style>
